prompt-helpers.bash

#!/usr/bin/env bash

function is_prompt_answer(){
    case "$1" in
        q|Q)return 1;;
        "")return 1;;
    esac
    return 0
}

##
#
# @deprecated in favor of is_prompt_answer
#
function is_quit_str(){
    if prompt_exited "$1";then
        return 0
    fi
    return 1
}

##
#
# @deprecated in favor of is_prompt_answer
#
#
# To print the answer and return when quit, use [prompt_exited "$response" -p && return;]
# To simply return in your function without printing anything: [prompt_exited "$response" && return;]
# @TODO add flag for using empty as a cancel as well
prompt_exited(){
	# @TODO add option to accept empty string (or possibly other "quit" responses
    if [[ "$2" == "-p" ]]; then
        shouldPrint=true;
    else
        shouldPrint=false;
    fi;
    case "$1" in
        n|N)
            $shouldPrint && msg_status "answered no"
            return 0
        ;;
        q|Q)
            $shouldPrint && msg_status "quitting"
            return 0
        ;;
        c|C)
            $shouldPrint && msg_status "canceled"
            return 0
        ;;
        "")
            $shouldPrint && msg_status "needed answer"
            return 0
        ;;
    esac
    return 1;
}